/*
 *The code is written by NaLi, All rights reserved.
 */
package com.nali.dal.statement.function.formatter;

import java.util.List;

import org.springframework.stereotype.Component;

import com.nali.dal.statement.function.DataHandler;
import com.nali.dal.statement.function.FunctionArgument;
import com.nali.dal.statement.function.FunctionException;

/**
 * @author gavin 
 * Created on 2011-4-9
 */
@Component
public class Nvl implements DataHandler<Object> {


	@Override
	public Object handle(List<Object> argList) throws FunctionException {
		Object data=argList.get(0);
		if(data==null) {
			data=argList.get(1);
		}
		return data;
	}

	@Override
	public void validate(List<FunctionArgument> arguments) throws FunctionException {
		if(arguments == null || arguments.size() != 2) {
			throw new FunctionException("Datahandler: " + this.getClass() +  ",Not valid argumetns: " + arguments);
		}
	}
}

